package com.xszx.controller;

import com.xszx.entity.Goods;
import com.xszx.entity.Role;
import com.xszx.entity.Shopping;
import com.xszx.entity.User;
import com.xszx.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @description:
 * @author:瓦达西瓦
 * @date:2024/10/31
 */
@Controller
@RequestMapping("/system")
public class SystemController {
    @Autowired
    private SystemService systemService;

//    展示不同类别的二手电子产品
    @RequestMapping("/getSort")
    @CrossOrigin(origins ="http://localhost:5173")
    @ResponseBody
    public List<Goods> getSort(Integer gtid){
         List<Goods> list=systemService.getSort(gtid);
         return list;
    }
   //获取角色表
   @RequestMapping("/getrole")
   @CrossOrigin(origins ="http://localhost:5173")
    @ResponseBody
   public List<Role> getrole(){
       List<Role> list=systemService.getrole();
       return list;
   }
   //获取用户购物车列表
   @RequestMapping("/getShoppping")
   @CrossOrigin(origins ="http://localhost:5173")
   @ResponseBody
   public List<Goods> getShoppping(String uid){
       System.out.println("购物车"+uid);
       User user= new User();
       user.setUid(Integer.valueOf(uid));
       List<Shopping> shoppingList=systemService.getShoppping(user);
       if(shoppingList.size()==0){
           return null;
       }else {
       List<Goods> list= systemService.getShoppping02(shoppingList);
       return list;
       }
   }

   //根据购物车商品的类型做推送
//    @RequestMapping("/getYouLove")
//    @CrossOrigin(origins ="http://localhost:5173")
//    @ResponseBody
//    public List<Goods> getYouLove(User user){
//        List<Goods> shoppingList=getShoppping(user);
//        if(shoppingList==null){
//            return null;
//        }else {
//            List<Goods> list = systemService.getYouLove(shoppingList);
//            return list;
//        }
//    }
   //获取当日总流水
    @RequestMapping("/getMoneySum")
    @CrossOrigin(origins ="http://localhost:5173")
    @ResponseBody
    public Object getMoneySum(){
      Double sum= systemService.getMoneySum();
       return sum;
    }


    //获取交易订单量
    @RequestMapping("/getOrdersSum")
    @CrossOrigin(origins ="http://localhost:5173")
    @ResponseBody
    public Object getOrdersSum(){
       Integer sum= systemService.getOrdersSum();
        return sum;
    }
    //查询总用户数量
    @RequestMapping("/getuserSum")
    @CrossOrigin(origins ="http://localhost:5173")
    @ResponseBody
    public Object getuserSum(){
        Integer sum= systemService.getuserSum();
        return sum;
    }

//    搜索引擎
    @RequestMapping("/search")
    @CrossOrigin(origins ="http://localhost:5173")
    @ResponseBody
    public Object getSearch(String search){
        List<Goods> goodsList=systemService.getGoodsSearch(search);
        return goodsList;
    }



}
